<template>
  <!-- 人员信息 -->
  <div class="container">
    <el-form ref="search" :inline="true" :model="formInline" :rules="rules" class="search" label-width="100px" size="small">
      <el-form-item label="用户名:">
        <el-input v-model="formInline.username" placeholder="请输入用户名" clearable />
      </el-form-item>
      <el-form-item label="部门:">
        <el-input v-model="formInline.departmentName" placeholder="请选择部门" @focus="showDept = true" />
        <!-- <el-row v-show="showDept" class="selDept">
          <i class="el-icon-circle-close" @click="showDept = false" />
          <el-tree :data="treeData" default-expand-all @node-click="selDept" />
        </el-row> -->
      </el-form-item>
      <el-form-item label="手机号:">
        <el-input v-model="formInline.phone" placeholder="请输入手机号" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="handleSearch">查询</el-button>
        <el-button type="primary" size="mini" @click="handlePerson">人员轨迹</el-button>
      </el-form-item>
    </el-form>
    <div class="table-wrap">
      <div class="f-betweenX table-header">
        <div class="table-title">
          <svg-icon icon-class="table_menu" class-name="icon-table" />
          <!-- 查询结果 共找到 <span class="count">{{ total }}</span> 条符合的记录 -->
          查询结果 共找到 <span class="count">5</span> 条符合的记录
        </div>
        <div class="table-control">
          <el-button type="primary" size="mini" icon="el-icon-download" plain>
            导入
          </el-button>
          <el-button type="primary" size="mini" icon="el-icon-upload2" plain>
            导出
          </el-button>
          <el-button type="primary" size="mini" icon="el-icon-plus" plain @click="handleAdd">
            新增
          </el-button>
        </div>
      </div>
      <!-- 表格 -->
      <tables :max-table-height="maxTableHeight" :table-data="tableData" />
    </div>
    <!-- 分页 -->
    <pagination :current="pageData.current" :size="pageData.size" :total="total" @changeSize="changeSize" @changeCurrent="changeCurrent" />
    <!-- 新增 -->
    <add ref="add" @refresh="refresh" />
  </div>
</template>

<script>
import Tables from './Tables.vue'
import Pagination from '@/components/Pagination'
import tableHeight from '@/mixins/tableHeight'
import pagination from '@/mixins/pagination'
import Add from './Add'
import TreeSelect from '@/components/TreeSelect'
import { getPersonnel } from '@/api/personnel'

export default {
  components: {
    Tables,
    Pagination,
    Add,
    TreeSelect
  },
  mixins: [tableHeight, pagination],
  data() {
    return {
      loding: false,
      total: 0,
      pageData: {
        current: 1,
        size: 10
      },
      formInline: {
        username: '',
        phone: '',
        deptId: [],
        startTime: '',
        endTime: ''
      },
      officeTreeList: this.$config.treeList, // 树形结构数据

      tableData: [
        {
          nickname: '9999',
          username: '9999',
          avatar: '',
          sex: '男',
          phone: '13800000000',
          role: '测试',
          dep: '技术部',
          email: '123456@123.com'
        },
        {
          nickname: '9129',
          username: '91299',
          avatar: '',
          sex: '女',
          phone: '13800000000',
          role: '技术',
          dep: '技术部',
          email: '1234561@123.com'
        },
        {
          nickname: '999',
          username: '999',
          avatar: '',
          sex: '女',
          phone: '13800670000',
          role: '测试',
          dep: '测试部',
          email: '1234562@123.com'
        },
        {
          nickname: '129',
          username: '91199',
          avatar: '',
          sex: '男',
          phone: '13801111110',
          role: '技术',
          dep: '技术部',
          email: '12345263@123.com'
        },
        {
          nickname: '9999',
          username: '9999',
          avatar: '',
          sex: '男',
          phone: '13801220000',
          role: '测试',
          dep: '技术部',
          email: '123452226@123.com'
        }
      ],
      showDept: false,
      treeData: []

      //   // 开始时间
      //   startTime: {
      //     disabledDate: time => {
      //       if (this.formInline.endTime) {
      //         return (
      //           time.getTime() > new Date(this.formInline.endTime).getTime()
      //         )
      //       } else {
      //         return time.getTime() > Date.now()
      //       }
      //     }
      //   },
      //   // 结束时间
      //   endTime: {
      //     disabledDate: time => {
      //       if (this.formInline.startTime) {
      //         return (
      //           time.getTime() > Date.now() ||
      //           time.getTime() < new Date(this.formInline.startTime).getTime()
      //         )
      //       } else {
      //         return time.getTime() > Date.now()
      //       }
      //     }
      //   }
    }
  },
  computed: {
    rules() {
      return {
        // startTime: [
        //   { required: true, message: "请选择开始时间", trigger: ["blur"] }
        // ],
        // endTime: [
        //   { required: true, message: "请选择结束时间", trigger: ["blur"] }
        // ]
      }
    }
  },
  mounted() {
    this.handleSearch()
  },
  methods: {
    // 查询
    handleSearch() {
      this.pageData.current = 1
      // this.getList()
    },
    // 人员轨迹
    handlePerson() {
      this.$router.push({ name: 'PersonRoute' })
    },
    // 刷新
    refresh() {
      this.handleSearch()
    },
    // 获取列表
    // getList() {
    //   const data = { ...this.pageData, ...this.formInline }
    //   console.log(1, data)
    //   getPersonnel(data)
    //     .then(res => {
    //       if (res.code === 0) {
    //         this.total = res.data.total
    //         this.tableData = res.data.records
    //       } else {
    //         this.$message.error(res.msg)
    //       }
    //     })
    //     .catch(err => {
    //       console.log(err)
    //     })
    // },
    // 获取部门名称
    popoverHide(checkedIds, checkedData, el) {
      if (el) {
        eval(' ( this.' + el + ' = checkedIds) ')
        console.log(1, this.formInline.deptId)
      }
    },
    onSubmit() {
      console.log('submit!')
    },
    // 新增
    handleAdd() {
      this.$refs.add.togglePopup(true)
    },
    // 选择部门
    selDept(dept) {
      // console.log('当前选择的部门', dept)
      // this.formInline.departmentName = dept.name
      this.showDept = false
    }

  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 0 17px;
  position: relative;
  .search {
    padding-top: 16px;
  }
  .table-wrap {
    .icon-table {
      margin: 0 10px;
    }
    .table-header {
      height: 52px;
      background: #f6f7f9;
      border: 1px solid #e1e7e9;
      border-bottom: none;
      font-size: 16px;
      color: #494949;
      line-height: 52px;
      border-radius: 4px 4px 0 0;
      .count {
        color: rgb(235, 104, 84);
      }
      .table-control {
        margin-right: 10px;
      }
    }
  }
  .pagination-wrap {
    height: 80px;
    .pagination {
      display: inline-block;
    }
  }
}
</style>

<style lang="scss">
.tree-line {
  .el-tree-node {
    position: relative;
    padding-left: 16px; // 缩进量
  }
  .el-tree-node__children {
    padding-left: 16px; // 缩进量
  }

  // 竖线
  .el-tree-node::before {
    content: '';
    height: 100%;
    width: 1px;
    position: absolute;
    left: -3px;
    top: -26px;
    border-width: 1px;
    border-left: 1px dashed #52627c;
  }
  // 当前层最后一个节点的竖线高度固定
  .el-tree-node:last-child::before {
    height: 38px; // 可以自己调节到合适数值
  }

  // 横线
  .el-tree-node::after {
    content: '';
    width: 24px;
    height: 20px;
    position: absolute;
    left: -3px;
    top: 12px;
    border-width: 1px;
    border-top: 1px dashed #52627c;
  }

  // 去掉最顶层的虚线，放最下面样式才不会被上面的覆盖了
  & > .el-tree-node::after {
    border-top: none;
  }
  & > .el-tree-node::before {
    border-left: none;
  }

  // 展开关闭的icon
  .el-tree-node__expand-icon {
    font-size: 16px;
    // 叶子节点（无子节点）
    &.is-leaf {
      color: transparent;
      // display: none; // 也可以去掉
    }
  }
}
.selDept {
  width: 178px;
  border: 1px solid #eee;
  .el-icon-circle-close {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 10;
    font-size: 18px;
    color: #666;
    cursor: pointer;
  }
}
</style>
